package com.xiaozhameng.openproject.qleexpress;

import com.ql.util.express.DefaultContext;
import com.ql.util.express.ExpressRunner;

/**
 * 功能描述：测试表达式解析
 *
 * @author: xiaozhameng
 * @date: 2021/1/7 12:17 下午
 */
public class ExpressRunnerTest {

    public static void main(String[] args) throws Exception {
        // 基本语法测试
        optExp01();

        optExp02();
    }

    /**
     * 基本测试2
     */
    private static void optExp02() throws Exception {
        ExpressRunner runner = new ExpressRunner();
        runner.addOperatorWithAlias("如果", "if",null);
        runner.addOperatorWithAlias("则", "then",null);
        runner.addOperatorWithAlias("否则", "else",null);

        String exp = "如果  (语文+数学+英语>270) 则 {return 1;} 否则 {return 0;}";
        DefaultContext<String, Object> context = new DefaultContext<String, Object>();
        Object execute = runner.execute(exp, context, null, false, false, null);
        System.out.println(execute);
    }

    /**
     * 基本测试
     */
    private static void optExp01() throws Exception {
        ExpressRunner runner = new ExpressRunner();
        DefaultContext<String, Object> context = new DefaultContext<String, Object>();
        context.put("a",1);
        context.put("b",2);
        context.put("c",3);
        String express = "a+b*c";
        Object r = runner.execute(express, context, null, true, false);
        System.out.println(r);
    }
}
